package controller;

import dao.retreatDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.RetreatDao;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/tuihuo")
public class tuihuo {
    @Autowired
    private dao.retreatDao retreatDao;
    @Autowired
    private RetreatDao RetreatDao;
    //查询退货信息
    @RequestMapping("/showTuiHou")
    @ResponseBody
    public Map<String,Object>showTuiHous(String seat,String th,String repertoryName,int offset,int limit){
        return showTuiHou(seat,th,repertoryName,offset,limit);
    }
    public Map<String,Object>showTuiHou(String seat,String th,String repertoryName,int offset,int limit){
        try {
            th = new String(th.getBytes("ISO-8859-1"), "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if(repertoryName!=null){
            try {
                repertoryName = new String(repertoryName.getBytes("ISO-8859-1"), "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        Map<String,Object> map=new HashMap<>();
        map.put("rows",retreatDao.showRetreat(th,seat,repertoryName,offset,limit));
        map.put("total",retreatDao.showtotal(th,seat,repertoryName));
        return map;
    }
    //审核退货信息
    @RequestMapping("/upTuiHou")
    @ResponseBody
    public Map<String,Object> upTuiHou(int Reteeatid, int save, String seat, String th, String repertoryName, int offset, int limit, HttpServletRequest request){
        RetreatDao.upretreat(Reteeatid,save,request);//退货流程
        return showTuiHou(seat,th,repertoryName,offset,limit);
    }
    //展示审核完的退货信息
    @RequestMapping("/shows")
    @ResponseBody
    public Map<String,Object>showth(String seat,String repertoryName,int offset,int limit){
        Map<String,Object> map=new HashMap<>();
        map.put("rows",retreatDao.showRetreats(seat,repertoryName,offset,limit));
        map.put("total",retreatDao.showtotals(seat,repertoryName));
        return map;
    }
}
